package com.jxzyk.util;

import com.core.util.L;

import android.text.Editable;
import android.text.TextWatcher;

/**
 * 判断输入框是否达到指定位数
 * 
 * @author Administrator
 * 
 */
public class NumberWatcher implements TextWatcher {
	private int size;
	private OnNumberWatcher onPhoneWatcher;

	public NumberWatcher(int size, OnNumberWatcher watcher) {
		this.size = size;
		this.onPhoneWatcher = watcher;
	}

	@Override
	public void afterTextChanged(Editable editable) {
		// if (editable.toString().length() == size) {
		// intput = true;
		// LogUtils.debug("输入数据之后监听");
		//
		// } else {
		// intput = false;
		// }
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// LogUtils.debug("输入数据之前的监听");
	}

	@Override
	public void onTextChanged(CharSequence s, int start, int count, int after) {
		System.out.println(s + "在输入数据时监听start:" + start + "/count:" + count
				+ "/after:" + after);
		// if ((start == size - 1) && s.length() == size) {
		// System.out.println("输入完毕");
		// if (onPhoneWatcher != null) {
		// onPhoneWatcher.onFinish();
		// }
		// }

		if (onPhoneWatcher != null) {
			if ((start == size - 1) && s.length() == size) {
				L.d("输入完毕");
				onPhoneWatcher.onFinish();
			} else {
				onPhoneWatcher.onProcess(s.length());
			}
		}
	}

}
